<template>
	<div class="page-wrap">
		<div class="page-inner">
			<div class="page-table-ctx-wrap">
				<!-- 控制器 -->
				<div class="actions-box">
					<div class="control-box">
						<div class="control-left">
							<div class="control-item">
								
									<div class="flex">
										<div class="action-item" style="margin-right: 20px;font-size: 14px;">
											已选 {{ selectedRows.length }} 个商品
										</div>
										<div class="action-item">
											<el-button type="primary" @click="do_submit()">批量审核通过</el-button>
										</div>
									</div>
								<!-- <el-button type="primary" @click="doAdd()">
									添加
								</el-button> -->
							</div>
						</div>
						<div class="control-right">
							<div class="action-item">
								<el-date-picker v-model="time_range" type="daterange" align="right" unlink-panels range-separator="至"
									start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
									:picker-options="pickerOptions">
								</el-date-picker>
							</div>
							<div class="action-item">
								<el-select clearable="" v-model="searchParams.type" placeholder="类型筛选" @change="select_type_onchange">
									<el-option v-for="item in type_select_options" :key="item.value" :label="item.title"
										:value="item.value">
									</el-option>
								</el-select>
							</div>
							<div class="action-item">
								<el-select clearable="" v-model="searchParams.status" placeholder="状态筛选"
									@change="select_status_onchange">
									<el-option v-for="item in status_select_options" :key="item.value" :label="item.title"
										:value="item.value">
									</el-option>
								</el-select>
							</div>
							<div class="action-item">
								<el-input clearable="" v-model="searchParams.keyword" placeholder="请输入关键词">
									<el-button slot="append" size="small" icon="el-icon-search" @click="doSearch()">
									</el-button>
								</el-input>
							</div>
							
							<div class="tab-wrap">
								<div class="actions">
									<el-button type="primary" @click="do_export_all()">导出所有</el-button>
									<el-button type="primary" @click="do_export_filter()">导出筛选</el-button>
								</div>
								
							</div>
							
							
						</div>
					</div>
				</div>
				<!-- 控制器 -->

				<!-- 渲染表格 -->
				<div class="table-view">


					<w_table :is_show_table_select="is_show_table_select" ref="w_table" @emitTable="emitTable" @onSelectionChange="onSelectionChange" />
				</div>
				<!-- 渲染表格 -->
				<div class="table-util">
					<div class="util-left">
						<!-- 批量选择 -->
					</div>
					<div class="util-right">
						<div class="pagi-item">
							<w_pagination v-if="tableData.length" :total="total" :pagination="pagination" @size-change="onSizeChange"
								@current-change="onCurrentChange" />
						</div>
					</div>
				</div>
			</div>
		</div>


		<w_form_modal ref="w_form_modal" @confirm="confirmFormSubmit" />


		<commission_audit_modal ref="commission_audit_modal" @confirm="setView" />
	</div>
</template>

<script>
	import commission_audit_modal from '@/components/user/commission/commission_audit_modal.vue'

	import page_config from "@/constant/user/commission/commission-withdrawal.js";
	import page_mixin from "@/mixins/page_mixin.js";
	export default {
		name: "banner",
		mixins: [page_mixin],
		components: {
			commission_audit_modal
		},
		data() {
			return {
				page_config,

				searchParams: {
					page: 1,
					pageNum: 10,
					type: -1, //0-提现银行卡 1-提现到零钱 -1-全部
					status: 0, //状态：2-待审核 3-审核成功 1-审核失败 0-全部
					keyword: '',
					startTime: '',
					endTime: '',
				},
				is_show_table_select:true,
				selectedRows: "",
				selectIds:"",

				type_select_options: [{
						title: '全部类型',
						value: -1,
					},
					{
						title: '提现银行卡',
						value: 0,
					},
					{
						title: '提现到零钱',
						value: 1,
					},
				],

				status_select_options: [{
						title: '全部状态',
						value: 0,
					},
					{
						title: '待审核',
						value: 2,
					},
					{
						title: '审核成功',
						value: 3,
					},
					{
						title: '审核失败',
						value: 1,
					},
				],
				//
				time_range: [],
				pickerOptions: {
					disabledDate(time) {
						return time.getTime() > Date.now();
					},
					shortcuts: [{
							text: "最近一周",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近一个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近三个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
								picker.$emit("pick", [start, end]);
							},
						},
					],
				},
			};
		},
		computed: {

		},
		watch: {
			time_range(value) {
				console.log('time_range', value)
				if (value && value.length) {
					this.searchParams.startTime = this.time_range[0] || ''
					this.searchParams.endTime = this.time_range[1] || ''
				} else {
					this.searchParams.startTime = ''
					this.searchParams.endTime = ''
				}
			}
		},
		created() {

		},
		mounted() {

		},
		methods: {
			format_list_data(list) {
				list.forEach(v => {
					let bankInfo = v.bankInfo || {}
					let userInfo = v.userInfo || {}
					v.cus_bankInfo_name = bankInfo.name
					v.cus_bankInfo_idCard = bankInfo.idCard
					v.cus_bankInfo_bankName = bankInfo.bankName
					v.cus_bankInfo_bankCard = bankInfo.bankCard
					
					v.cus_user_realName = userInfo.realName||userInfo.nickname
					v.cus_user_phone = userInfo.phone
					
					
					
				})
			},
			doRowOther(row, action_title) {
				if (action_title == '审核') {
					this.$refs.commission_audit_modal.init(row)
				}
			},
			
			do_submit() {
				this.$confirm('确认要审核通过吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.do_tongguo();
				}).catch(() => {
				
				});
			},
			
			do_tongguo(){
				this.$api({
					url: '/admin_service.php',
					method: 'get',
					data: {
						action: "users_tixianHexiaoPiliang",
						id: this.selectIds,
						status:3
					}
				}).then(res => {
					if (res.code == 200) {
						this.setView();
						this.$message({
							message: res.msg,
							type: 'success'
						})
					} else {
						alertErr(res.msg)
					}
				})
			},
			
			onSelectionChange(selectedRows) {
				console.log(selectedRows,'2000')
				this.selectedRows = selectedRows
				let selectIds=selectedRows.map(v=>v.id)
				this.selectIds = selectIds.join(",")
				console.log(this.selectIds,'selectIds00')
			},
			
			do_export_all() {
				let token = this.mix_get_token()
				let url =
					`${this.API_ROOT}?action=users_exportTixianForm&page=1&pageSize=1000000&level=&keyword=&startTime=&endTime=&token=${token}`
				window.open(url, '_blank')
			},
			
			do_export_filter() {
				let token = this.mix_get_token()
				let startTime = this.time_range[0] || ''
				let endTime = this.time_range[1] || ''
				
				let url =
					`${this.API_ROOT}?action=users_exportTixianForm&page=1&pageSize=1000000&level=&keyword=${this.keyword}&startTime=${startTime}&endTime=${endTime}&token=${token}`
				window.open(url, '_blank')
			},

			select_type_onchange() {
				this.initQuery()
			},
			select_status_onchange() {
				this.initQuery()
			}
		},
	};
</script>

<style scoped lang="less">
	// /deep/ .el-table table {
	//   width: 100% !important;

	//   thead {
	//     th.el-table__cell {
	//       background: #f8f8f8;
	//       color: #000;
	//     }
	//   }
	// }


	.page-table-ctx-wrap {
		background: #fff;
		padding: 20px;
		border-radius: 6px;
	}

	// 新增
	.control-box {
		.flex-between();

		.control-left {
			.flex();

			.control-item {
				margin-right: 10px;
			}
		}

		.control-right {
			.flex();

			.action-item {
				margin-left: 10px;
			}
		}
	}

	.table-view {
		margin-top: 20px;
		margin-bottom: 20px;
	}


	// 表格工具栏
	.table-util {
		.flex-between();

		.util-left {
			.flex();
			min-width: 100px;

			.util-items {
				.flex();

				.item {
					margin-right: 10px;
				}
			}
		}

		.util-right {}
	}
</style>